{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "SUGRA_Colab.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7TM86YdFURjU"
      },
      "source": [
        "Copyright 2021 Google LLC\n",
        "\n",
        "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "you may not use this file except in compliance with the License.\n",
        "You may obtain a copy of the License at\n",
        "\n",
        "    https://www.apache.org/licenses/LICENSE-2.0\n",
        "\n",
        "Unless required by applicable law or agreed to in writing, software\n",
        "distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "See the License for the specific language governing permissions and\n",
        "limitations under the License.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NzMg0SqLWmjp",
        "cellView": "form"
      },
      "source": [
        "#@title Initialization\n",
        "reset_package = False #@param {type:\"boolean\"}\n",
        "package_url = \"https://github.com/google-research/google-research/trunk/m_theory\" #@param {type:\"string\"}\n",
        "package_source = \"Fetch from Repository\" #@param [\"Upload from Computer\", \"Fetch from Repository\"]\n",
        "\n",
        "import glob\n",
        "import os\n",
        "import shlex\n",
        "import shutil\n",
        "import subprocess\n",
        "import time\n",
        "\n",
        "\n",
        "def _get_archive_via_upload(filename='m_theory.zip'):\n",
        "  from google.colab import files\n",
        "  while True:\n",
        "    print('Please upload', filename)\n",
        "    uploaded = files.upload()\n",
        "    print('Uploaded:', {k: len(v) for k, v in uploaded.items()})\n",
        "    if filename in uploaded:\n",
        "      break\n",
        "  subprocess.call(['unzip', filename])\n",
        "\n",
        "\n",
        "def _get_archive_from_repository(url=None):\n",
        "  import os\n",
        "  import shlex\n",
        "  if url is None:\n",
        "    url = package_url\n",
        "  os.system('[ -f /usr/bin/svn ] || apt install subversion')  # Subshell!\n",
        "  subprocess.run(['/usr/bin/svn', 'export', url])\n",
        "\n",
        "###\n",
        "for filename in glob.glob('*.zip'):\n",
        "  print('Removing:', filename)\n",
        "  os.unlink(filename)\n",
        "\n",
        "if reset_package:\n",
        "  try:\n",
        "    shutil.rmtree('m_theory')\n",
        "  except OSError:\n",
        "    pass\n",
        "\n",
        "while not os.access('m_theory', os.X_OK):\n",
        "  time.sleep(0.5)  # If something goes wrong here, do not fast-loop-on-failure.\n",
        "  print('Obtaining package...')\n",
        "  if package_source.startswith('Upload '):\n",
        "    _get_archive_via_upload()\n",
        "  elif package_source.startswith('Fetch '):\n",
        "    _get_archive_from_repository(package_url)\n",
        "  else:\n",
        "    print('Mangled package source, aborting.')\n",
        "    break\n",
        "\n",
        "if os.access('m_theory', os.X_OK):\n",
        "  print('Archive is available.')\n",
        "  # Symlink things upwards into the current directory.\n",
        "  for filename in sorted(os.listdir('m_theory')):\n",
        "    try:\n",
        "      os.symlink(os.path.join('m_theory', filename), filename)\n",
        "    except OSError:\n",
        "      pass"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eNkW3-iper88"
      },
      "source": [
        "import numpy\n",
        "import tensorflow as tf\n",
        "from m_theory_lib import m_util as mu\n",
        "from m_theory_lib import algebra\n",
        "from m_theory_lib import supergravity\n",
        "from dim4.so8.src import dyonic\n",
        "\n",
        "\n",
        "# Demo: Scan some critical points of SO(8)c supergravity for omega=pi/8.\n",
	"# The SL(2)x7 trajectory code is at: dim4/papers/bfis2021/analyze_sl2x7.py\n",
        "sugra = dyonic.SO8c_SUGRA()\n",
        "t_omega=mu.tff64(numpy.pi*0.125)\n",
        "\n",
        "for nn, (pot, stat, pos) in zip(range(10), sugra.scan(t_omega=t_omega)):\n",
        "  if stat > 1e-8:\n",
        "    continue\n",
        "  phys = sugra.get_physics(pos, {}, t_omega=t_omega)\n",
        "  print(sugra.show_physics_text(phys))\n"
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}